#ifndef INTERPRETER_HPP
#define INTERPRETER_HPP

#include "config.h"
#include "guish_classproto.hpp"
#include "shared_classproto.hpp"

#include "Builtin.hpp"
#include "ExecutionEnvironment.hpp"
#include "Expansion.hpp"
#include "Job.hpp"
#include "Path.hpp"
#include "ShellCommand.hpp"
#include "ShellState.hpp"
#include "Tokenizer.hpp"

// From ../shared
#include "RPC.hpp"

// From gen
#include "grammar.h"

int commandContinuationLines(const char *cmd);
int executeFile(const char *filename, ExecutionEnvironment *execEnv, Job *context);
int executeText(const char *cmd, ExecutionEnvironment *execEnv, Job *context);

struct ParserContext
{
public:
	ParserContext(const char *text, ShellState *state);
	~ParserContext();
	int yylex(YYSTYPE *lvalp, YYLTYPE *llocp);
	Token getToken(int index) const;
	Tokenization *getTokenization();
	
	SequenceCommand *result;
	
protected:
	void tokenizeMore();
	
	char *text;
	int currentToken;
	Tokenization tokenization;
};

int yyparse(ParserContext *context);
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, ParserContext *context);
int yyerror(YYLTYPE *locp, ParserContext *context, const char *msg);
void interactiveParserTest();

// Special exit status codes
// (copied from bash-3.2)
#define EX_BADUSAGE 2

#define EX_BINARY_FILE  126
#define EX_NOEXEC   126
#define EX_NOINPUT  126
#define EX_NOTFOUND 127

#define EX_BADSYNTAX    257 // shell syntax error
#define EX_USAGE        258 // syntax error in usage
#define EX_REDIRFAIL    259 // redirection failed
#define EX_BADASSIGN    260 // variable assignment error
#define EX_EXPFAIL      261 // word expansion failed

#endif
